package controller;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;
/**
 * Servlet implementation class CBAServlet
 */
@WebServlet("/CBAServlet")
public class CBAServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

    /**
     * Default constructor. 
     */
    public CBAServlet() {
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.getWriter().append("Served at: ").append(request.getContextPath());
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	      // 设置请求编码格式
	      request.setCharacterEncoding("UTF-8");
	      // 设置响应编码格式
	      response.setContentType("text/html;charset=UTF-8");
	      // 获取响应输出流
	      PrintWriter writer = response.getWriter();
	      // 生成HTML代码
	      writer.append("<!DOCTYPE html>")
	            .append("<html>")
	            .append("<head>")
	            .append("<title>HTTP响应</title>")
	            .append("</head>")
	            .append("<body>")
	            .append("<h1>HTTP响应</h1>")
	            .append("</body>")
	            .append("</html>");
	}
}
